<template>
  <div class="operateMsg">
    <!-- 搜索 -->
    <div class="search">
      <div class="searchVal">
        <p>消息时间</p>
        <el-date-picker
          style="margin-right: 20px"
          v-model="TimeVal"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd"
          @change="focus"
        >
        </el-date-picker>
      </div>
      <div class="searchVal">
        <p>消息状态</p>
        <el-select v-model="checkVal" placeholder="不限">
          <el-option label="已读" value="1"> </el-option>
          <el-option label="未读" value="2"> </el-option>
        </el-select>
      </div>
      <el-button @click="search">查询</el-button>
    </div>
    <!-- 列表 -->
    <el-card>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%; margin-top: 10px"
        :header-cell-style="{ background: '#f5f7fa' }"
      >
        <el-table-column align="center" prop="create_time" label="创建时间">
        </el-table-column>
        <el-table-column align="center" prop="title" label="标题">
        </el-table-column>
        <el-table-column align="center" prop="id" label="正文">
          <template slot-scope="scope">
            <el-button
              type="primary"
              plain
              size="small"
              @click="look(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="page"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 消息详情弹框 -->
    <el-dialog title="内容详情" :visible.sync="dialogFormVisible" width="35%">
      <div v-html="html"></div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >确定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { AdminUnionMessageList } from "@/api/union";
import Pagination from "@/components/Pagination"; // 分页
export default {
  components: { Pagination },
  data() {
    return {
      TimeVal: "", //时间日期选择
      //   日期时间选择器数组
      pickerOptions: {
        disabledDate(platformValue) {
          return platformValue.getTime() > Date.now() - 8.64e6;
        },
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      timeStart: "", //开始时间
      timeEnd: "", //结束时间
      checkVal: "", //消息状态

      loading: false,
      tableData: [],
      page: 1, //当前页
      pageSize: 15, //当前页条数
      total: 0, //总计
      dialogFormVisible: false,
      html: "",
    };
  },
  created() {
    this.getlMessageList();
  },
  methods: {
    //获取开始/结束时间
    focus(time) {
      if (!this.TimeVal) {
        this.TimeVal = [];
      }
      this.timeStart = this.TimeVal[0];
      this.timeEnd = this.TimeVal[1];
    },

    // 获取列表
    async getlMessageList() {
      this.loading = true;
      let { code, data } = await AdminUnionMessageList({
        state: 1,
        page: this.page,
        pageSize: this.pageSize,
        startTime: this.timeStart,
        endTime: this.timeEnd,
      });
      if (code == 0) {
        console.log(data, "9527");
        this.tableData = data.list;
        this.total = parseInt(data.count);
        this.loading = false;
      }
    },

    getList() {
      this.getlMessageList();
    },
    search() {
      this.getList();
    },

    // 消息详情
    look(row) {
      this.dialogFormVisible = true;
      this.html = row.content;
    },
  },
};
</script>

<style lang="less" scoped>
.operateMsg {
  margin: 30px;
  height: 100%;
  .search {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 30px;
    .searchVal {
      display: flex;
      p {
        width: 80px;
        text-align: center;
        border: 1px solid #dcdfe6;
        border-right: 0px;
        height: 40px;
        line-height: 20px;
        margin: 0px;
        background: #f5f7fa;
        color: #909399;
        font-size: 14px;
        padding: 10px;
        border-radius: 4px 0px 0px 4px;
      }
    }
    /deep/.el-input {
      width: 260px;
      margin-right: 30px;
    }
    /deep/.el-button {
      margin-left: 30px;
    }
  }
}
.main {
  cursor: pointer;
  .head {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    p {
      margin-right: 15px;
      font-size: 18px;
      font-weight: bold;
    }
  }
  .content {
    width: 40%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
</style>